package jflowmap.model.ontology;

import jflowmap.FlowMapColorSchemes;
import jflowmap.data.ViewConfig;
import jflowmap.model.geo.MapProjections;
import jflowmap.model.map.GeoMap;
import jflowmap.views.AbstractView;
import jflowmap.views.IFlowMapColorScheme;
import jflowmap.views.MapBackgroundImage;
import jflowmap.views.flowmap.FlowMapView;
import jflowmap.views.flowmap.VisualFlowMapModel;
import jflowmap.views.heatmap.HeatMapView;
import jflowmap.views.quadrant.SpiralView;

public enum ViewTypes {

	PIES {
		@Override
		public AbstractView create(final String name, final ViewConfig config, GeoMap areaMap) throws Exception {
			return new FlowMapView(name, MapBackgroundImage.parseConfig(config),
								   areaMap, mapProjection(config), colorSchemeFor(config), config);
		}
	},
	
	QUADRANTS {
		@Override
		public AbstractView create(final String name, ViewConfig viewConfig, GeoMap areaMap) {
			return new SpiralView(name, viewConfig);
		}
		
	},
	
	HEATMAPS {
		@Override
		public AbstractView create(final String name, final ViewConfig config, GeoMap areaMap) throws Exception {
			return new HeatMapView(name, MapBackgroundImage.parseConfig(config), areaMap, mapProjection(config), config);
		}
		
	};
	
	public abstract AbstractView create (final String name, final ViewConfig viewConfig, final GeoMap areaMap) throws Exception;
	
	private static IFlowMapColorScheme colorSchemeFor(ViewConfig config) {
		return FlowMapColorSchemes.findByName(
				config.getStringOrElse(VisualFlowMapModel.VIEWCONF_COLOR_SCHEME, "Standard"));
	}

	private static MapProjections mapProjection(ViewConfig config) throws Exception {
		String projName = config.getStringOrElse(ViewConfig.PROP_MAP_PROJECTION, "None").toUpperCase();
		MapProjections proj = MapProjections.valueOf(
				projName);
		if (proj == null) {
			System.out.println("Projection '" + projName + "' is not supported");
		}
		return proj;
	}
}
